package cn.shujuhai.cms.service.thymeleaf;

import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;

/**
 * @Author: NiuYaHu
 * @Date: 2025/2/19 16:25
 * @Description: 国际化Service
 **/
@Service
public class InternationService {
    public Map<String, String> greeting(String acceptLanguage) {
        Locale locale = Locale.forLanguageTag(acceptLanguage);  // 创建对应的Locale对象
        ResourceBundle bundle = ResourceBundle.getBundle("messages", locale);
        Map<String, String> messages = new HashMap<>();
        bundle.keySet().forEach(key -> messages.put(key, bundle.getString(key)));
        return messages;
    }
}
